<template>
  <div class="p-2">
    <el-card class="box-card">
      <template v-slot:header>
        <div class="clearfix">
          <el-tabs v-model="tableFrom.checked" @tab-click="seachList" >
            <el-tab-pane
              :label="item.name"
              :name="item.type.toString()"
              v-for="(item, index) in headeNum"
              :key="index"
            />
          </el-tabs>
          <el-form inline size="small">
              <el-form-item label="商品搜索：">
                <el-input
                  v-model="tableFrom.keywords"
                  placeholder="请输入商品ID，商品名称，关键字"
                  style="width: 270px;padding-right: 20px;"
                  size="small"
                  clearable
                >

                </el-input>
                <el-button type="primary" size="small" @click="getList">查询</el-button>
              </el-form-item>
            </el-form>
        </div>
      </template>
      <el-table
        v-loading="listLoading"
        :data="tableData.data"
        style="width: 100%"
        size="small"
        :highlight-current-row="true"
        :header-cell-style="{ fontWeight: 'bold' }"
      >
        <!-- <el-table-column type="index"/> -->
        <el-table-column prop="id" label="商品ID" min-width="60"/>
        <el-table-column label="商品图" min-width="80" >
          <template #default="{row}">
            <div class="demo-image__preview">
              <el-image
                style="width: 36px; height: 36px"
                :src="row.image"
                :preview-src-list="[row.image]"
              />
            </div>
          </template>
        </el-table-column>
        <el-table-column
          label="商品名称"
          prop="storeName"
          min-width="300"
          :show-overflow-tooltip="true"
        >
        </el-table-column>

        <el-table-column
          prop="price"
          label="商品销售价(元)"
          min-width="110"
          align="center"
        />
        <el-table-column
          prop="cost"
          label="商品成本价(元)"
          min-width="110"
          align="center"
        />
        <el-table-column
          prop="stock"
          label="库存"
          min-width="90"
          align="center"
        />
        <el-table-column
          prop="tenantName"
          label="供应商"
          min-width="90"
          align="center"
        />
        <el-table-column label="审核状态" min-width="80" align="center">
          <template #default="{row}">
            <span>{{ checkedFilterHandle(row.checked)}}</span>
          </template>
        </el-table-column>
        <el-table-column label="不通过原因" min-width="150"  v-if = "tableFrom.checked == 2" align="center">
          <template #default="{row}">
            <span>{{ row.noPassReason}}</span>
          </template>
        </el-table-column>
        <!-- <el-table-column label="审核时间" min-width="150" align="center">
          <template #default="{row}">
            <span>{{ row.checkTime}}</span>
          </template>
        </el-table-column> -->
        <el-table-column label="操作" min-width="200" fixed="right" v-if = "tableFrom.checked == 3" align="center">
          <template #default="{row}">
            <div>
              <router-link :to="{ path: '/shopping/store/shoppingStoreCreatMerchantStore/' + row.id + '/1' }">
                <el-button type="primary" text size="small" class="mr10" >详情</el-button>
              </router-link>
              <el-button
                v-if="row.checked === 3"
                type="primary"
                size="small"
                @click="onchangePass(row)"
                >通过</el-button
              >
              <el-button
                v-if="row.checked === 3"
                type="danger"
                size="small"
                @click="onchangeNoPass(row)"
                >拒绝</el-button
              >
            </div>
          </template>
        </el-table-column>
      </el-table>
      <div class="block">
        <el-pagination
          :page-sizes="[20, 40, 60, 80]"
          :page-size="tableFrom.limit"
          :current-page="tableFrom.page"
          layout="total, sizes, prev, pager, next, jumper"
          :total="tableData.total"
          @size-change="handleSizeChange"
          @current-change="pageChange"
        />
      </div>
    </el-card>
    <el-dialog
      title="拒绝通过原因"
      v-if="refuseVisible"
      v-model="refuseVisible"
      width="500px"
      :before-close="refusehandleClose"
    >
    <el-form
        ref="refuseFormValue"
        class="formValidate mt20"
        :model="refuseFormValue"
        label-width="120px"
        @submit="refusehandlerSubmit"
        @resetForm="resetFormRefusehand"
      >
        <el-row :gutter="24">
          <!-- 商品信息-->
          <el-col v-bind="grid2">
            <el-form-item label="商品ID:" prop="id">
              <el-input
                v-model="refuseFormValue.id"
                maxlength="249"
                placeholder="商品ID"
                :disabled="true"
              />
            </el-form-item>
          </el-col>
          <el-col v-bind="grid2">
            <el-form-item label="拒绝原因：" prop="reason">
              <el-input
                v-model="refuseFormValue.reason"
                maxlength="32"
                placeholder="拒绝原因"
                :disabled="false"
              />
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item>
              <el-button
                type="primary"
                @click="refusehandlerSubmit"
                >确认
              </el-button>
              <el-button
                type="info"
                @click="refusehandleClose"
                >取消
              </el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import {
  productExamineLstApi,
  examinePassApi,
  examineNoPassApi
} from '@/api/shopping/store';

export default {
  name: 'ExamineGoodsList',
  data() {
    return {
      props: {
        children: 'child',
        label: 'name',
        value: 'id',
        emitPath: false,
      },
      headeNum: [
        { count: 3, name: "审核中", type: 3 },
        { count: 1, name: "审核通过", type: 1 },
        { count: 2, name: "审核不通过", type: 2 }
      ],
      refuseVisible: false,
      refuseData: {},
      refuseFormValue:Object.assign({}, this.refuseData),
      listLoading: true,
      tableData: {
        data: [],
        total: 0,
      },
      tableFrom: {
        page: 1,
        limit: 20,
        cateId: '',
        keywords: '',
        type: 1,
        checked: 3
      },
      categoryList: [],
      dialogVisible: false,
      checkAll: false,
      checkedCities: ['ID', '商品图', '商品名称', '商品销售价', '销量', '库存', '排序', '状态', '操作时间'],
      columnData: ['ID', '商品图', '商品名称', '商品销售价', '销量', '库存', '排序', '状态', '操作时间'],
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    seachList(tab) {
      if (tab) {
        this.tableFrom.checked = Number(tab.paneName);
      }
      console.log(this.tableFrom.checked);
      this.tableFrom.page = 1;
      this.getList();
    },
    //列表
    getList() {
      this.listLoading = true;
      productExamineLstApi(this.tableFrom)
        .then((res) => {
          this.tableData.data = res.data.list;
          this.tableData.total = res.data.total;
          this.listLoading = false;
        })
        .catch((res) => {
          this.listLoading = false;
        });
    },
    pageChange(page) {
      this.tableFrom.page = page;
      this.getList();
    },
    handleSizeChange(val) {
      this.tableFrom.limit = val;
      this.getList();
    },
    onchangePass(row) {
      examinePassApi(row.id)
        .then(() => {
          ElMessage.success('审核完成');
          this.getList();
        })
        .catch(() => {
        })
    },
    onchangeNoPass(row) {
      this.orderids = row.orderId;
      this.refuseData = {
        id: row.id,
        reason: '',
      };
      this.refuseFormValue=Object.assign({}, this.refuseData),
      this.refuseVisible = true;
    },
    resetFormRefusehand() {
      this.refuseVisible = false;
    },
    // 拒绝通过
    refusehandleClose() {
      this.refuseVisible = false;
    },
    refusehandlerSubmit() {
      examineNoPassApi({id:this.refuseFormValue.id,reason: this.refuseFormValue.reason }).then(() => {
        ElMessage.success('操作成功');
        this.refuseVisible = false;
        this.getList();
      });
    },
    //0：未审核，1:审核通过，2：审核不通过；3、审核中
    checkedFilterHandle(value) {
      if (value == '0') {
        return '未审核'
      } else if (value == '1') {
        return '通过'
      }else if (value == '2') {
        return '不通过'
      }else if (value == '3') {
        return '审核中'
      }
    },
  },
};
</script>

<style scoped lang="scss">
@import "../../../assets/styles/styles.scss";
.el-table__body {
  width: 100%;
  table-layout: fixed !important;
}
.demo-table-expand {
  padding-left: 60px;
  :deep( label) {
    width: 82px;
  }
}
.demo-table-expand {
  :deep( .el-form-item__content) {
    width: 77%;
  }
}
.selWidth {
  width: 250px !important;
}
.seachTiele {
  line-height: 30px;
}
.relative {
  position: relative;
}
.card_abs {
  position: absolute;
  padding-bottom: 15px;
  top: 260px;
  right: 40px;
  width: 200px;
  background: #fff;
  z-index: 99999;
  box-shadow: 0px 0px 14px 0px rgba(0, 0, 0, 0.1);
}
.cell_ht {
  height: 50px;
  padding: 15px 20px;
  box-sizing: border-box;
  border-bottom: 1px solid #eeeeee;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.check_cell {
  width: 100%;
  padding: 15px 20px 0;
}
.mt-1 {
  margin-top: 6px;
}
:deep(.el-checkbox__input.is-checked + .el-checkbox__label) {
  color: #606266;
}
</style>
